/*******************************************************************************
 * Copyright (c) 2014 Joel Thurlby.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Joel Thurlby - initial API and implementation
 ******************************************************************************/
package jat.xtext.gantt.ui.diagram;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.nebula.widgets.ganttchart.GanttEvent;
import org.eclipse.nebula.widgets.ganttchart.GanttEventListenerAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.xtext.resource.DefaultLocationInFileProvider;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
import org.eclipse.xtext.util.ITextRegion;

public class GanttChartListener extends GanttEventListenerAdapter {
	public GanttChartListener(GanttChartViewer viewer) {
		
	}
	
	@Override
	public void eventDoubleClicked(GanttEvent event, MouseEvent mouseEvent) {
		DefaultLocationInFileProvider prov = new DefaultLocationInFileProvider();
		ITextRegion region = prov.getFullTextRegion((EObject) event.getData());
		int offset = region.getOffset();
		int length = region.getLength();
		XtextEditor editor = EditorUtils.getActiveXtextEditor();
		if (editor != null) {
			editor.setHighlightRange(offset, length, true);
		}
	}
}
